// 数组 signData 加额外标记 _data[0] 作为链表实现栈的结构
const signData = [];
const maxCount = 128;
const POINTER_INVALID_FLAG = 65535;
const POS_NEXT_FREE = 0;
const POS_FREE_FLAG = 1;
const SPACE_FREE_FLAG = 0;
const SPACE_USE_FLAG = 1;
const _data = [0, 0];
for (let k = 0; k < maxCount; k++) {
  signData[k * 2 + POS_NEXT_FREE] = k + 1;
  signData[k * 2 + POS_FREE_FLAG] = SPACE_FREE_FLAG;
}
signData[(maxCount - 1) * 2] = POINTER_INVALID_FLAG;
const isAllFree = () => 0 === _data[1];
const hasSpace = () => POINTER_INVALID_FLAG === _data[0];
const pop = () => {
  const index = _data[0];
  if (index === POINTER_INVALID_FLAG) return;
  const point = index * 2;
  signData[point + POS_FREE_FLAG] = SPACE_USE_FLAG;
  _data[0] = signData[point];
  _data[1]++;
  return index;
};
const push = (index) => {
  const point = index * 2;
  signData[point + POS_FREE_FLAG] = SPACE_FREE_FLAG;
  signData[point] = _data[0];
  _data[0] = index;
  _data[1]--;
};
